home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 60 / IOPROG_60.ISO / soft / c++ / gsl-1.1.1-setup.exe / {app} / src / ieee-utils / fp-freebsd.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-07-20  |  2.5 KB  |  103 lines

  1. /* ieee-utils/fp-freebsd.c
  2.  * 
  3.  * Copyright (C) 2000 Vladimir Kushnir
  4.  * 
  5.  * This program is free software; you can redistribute it and/or modify
  6.  * it under the terms of the GNU General Public License as published by
  7.  * the Free Software Foundation; either version 2 of the License, or (at
  8.  * your option) any later version.
  9.  * 
  10.  * This program is distributed in the hope that it will be useful, but
  11.  * WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.  * General Public License for more details.
  14.  * 
  15.  * You should have received a copy of the GNU General Public License
  16.  * along with this program; if not, write to the Free Software
  17.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  */
  19.  
  20. #include <ieeefp.h>
  21. #include <gsl/gsl_ieee_utils.h>
  22. #include <gsl/gsl_errno.h>
  23.  
  24. int
  25. gsl_ieee_set_mode (int precision, int rounding, int exception_mask)
  26. {
  27.   fp_prec_t prec = 0 ;
  28.   fp_except_t mode = 0 ;
  29.   fp_rnd_t    rnd  = 0 ;
  30.  
  31.   switch (precision)
  32.     {
  33.     case GSL_IEEE_SINGLE_PRECISION:
  34.       prec = FP_PS;
  35.       fpsetprec(prec);      
  36.       break ;
  37.     case GSL_IEEE_DOUBLE_PRECISION:
  38.       prec = FP_PD;
  39.       fpsetprec(prec);
  40.       break ;
  41.     case GSL_IEEE_EXTENDED_PRECISION:
  42.       prec = FP_PE;
  43.       fpsetprec(prec);
  44.       break ;
  45.     }
  46.  
  47.   switch (rounding)
  48.     {
  49.     case GSL_IEEE_ROUND_TO_NEAREST:
  50.       rnd = FP_RN ;
  51.       fpsetround (rnd) ;
  52.       break ;
  53.     case GSL_IEEE_ROUND_DOWN:
  54.       rnd = FP_RM ;
  55.       fpsetround (rnd) ;
  56.       break ;
  57.     case GSL_IEEE_ROUND_UP:
  58.       rnd = FP_RP ;
  59.       fpsetround (rnd) ;
  60.       break ;
  61.     case GSL_IEEE_ROUND_TO_ZERO:
  62.       rnd = FP_RZ ;
  63.       fpsetround (rnd) ;
  64.       break ;
  65.     default:
  66.       rnd = FP_RN ;
  67.       fpsetround (rnd) ;
  68.     }
  69.  
  70.   /* Turn on all the exceptions apart from 'inexact' */
  71.  
  72.   mode = FP_X_INV | FP_X_DNML | FP_X_DZ | FP_X_OFL | FP_X_UFL ;
  73.  
  74.   if (exception_mask & GSL_IEEE_MASK_INVALID)
  75.     mode &= ~ FP_X_INV ;
  76.  
  77.   if (exception_mask & GSL_IEEE_MASK_DENORMALIZED)
  78.     mode &= ~ FP_X_DNML ;
  79.  
  80.   if (exception_mask & GSL_IEEE_MASK_DIVISION_BY_ZERO)
  81.     mode &= ~ FP_X_DZ ;
  82.  
  83.   if (exception_mask & GSL_IEEE_MASK_OVERFLOW)
  84.     mode &= ~ FP_X_OFL ;
  85.  
  86.   if (exception_mask & GSL_IEEE_MASK_UNDERFLOW)
  87.     mode &=  ~ FP_X_UFL ;
  88.  
  89.   if (exception_mask & GSL_IEEE_TRAP_INEXACT)
  90.     {
  91.       mode |= FP_X_IMP ;
  92.     }
  93.   else
  94.     {
  95.       mode &= ~ FP_X_IMP ;
  96.     }
  97.  
  98.   fpsetmask (mode) ;
  99.  
  100.   return GSL_SUCCESS ;
  101.  
  102. }
  103.